<template>
	<view class="wrap">
		<!-- 修改用户昵称 -->
		<u-input v-model="userName" type="text" :border="border" placeholder="请输入昵称" />
		<u-button type="primary" @click="confirmName()" :disabled="userNameIsNull==true">确认修改</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName: '',
				border: true,
			}
		},
		methods: {
		    async confirmName(){
				const params={
					name:this.userName
				}
				await this.$u.put('/api/user',params).then(res=>{
					uni.showToast({
						title:'修改成功',
						icon:'success'
					})
					this.$u.vuex('vuex_user.name',this.userName)
					uni.$on('send',res=>{
						uni.$emit('userInfoName',this.userName)
					})
					setTimeout(res=>{
						uni.$u.route({
							type: 'switchTab',
							url: 'pages/me/me'
						})
					},1000)
					
				}).catch(err=>{
					console.log(err)
				})
			}
		},
		computed:{
			userNameIsNull(){
				return !this.userName
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 40rpx;
	}
	.u-input{
		margin-bottom: 40rpx;
	}
</style>
